package a10_动态规划;

/**
 * <p>
 * a08_整数拆分复习3
 * </p>
 *
 * @author flyduck
 * @since 2025/3/27
 */
public class a08_整数拆分复习3 {

    public static void main(String[] args) {
        System.out.println(integerBreak(10));
    }
    //dp[j]：和为n的最大乘积

    //递推公式：
    //i * (j-i)
    //dp[i] * (j-i)
    public static int integerBreak(int n) {
        int[] dp = new int[n+1];
        dp[0] = 0;
        dp[1] = 1;

        for (int j = 1; j <= n; j++) {
            for (int i = 1; i < j; i++) {
                dp[j] = Math.max(dp[j],Math.max(i, dp[i]) * (j-i));
            }
        }

        return dp[n];
    }
}
